<!--
 * @Description: 泵车维护
 * @Author: wangwangwang
 * @Date: 2020-09-21 14:09:06
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2021-12-29 14:33:53
-->
<template>
  <div class="pages_content table">
    <el-container>
      <el-header>
        <breaDcrumb />
      </el-header>
      <el-main>
        <div class="header_right" @click="showCardNav = !showCardNav">
          <div class="title">搜索</div>
          <div>
            <div :class="{ 'arrowTransform': !showCardNav, 'arrowTransformReturn': showCardNav}">
              <i style="margin-right: 5px" class="el-icon-arrow-down"></i>
            </div>
          </div>
        </div>
        <div v-show="showCardNav" class="hr"></div>
        <el-collapse-transition>
          <div v-show="showCardNav">
            <div class="search">
              <span style="display: inline-block;margin-bottom: 10px;">
                <span style="margin-right: 12px;">泵编码</span>
                <el-input v-model="tableParam.code" style="width: 240px;" clearable placeholder="请输入" @keyup.enter.native="gettableData()" />
              </span>
              <span style="margin-left: 24px;">
                <span style="margin-right: 12px;">泵车类型</span>
                <el-select v-model="tableParam.facilityTypeId" style="width: 160px;" placeholder="请选择">
                  <el-option v-for="item in equipmentTypelist" :key="item.id" :label="item.itemName" :value="item.id"></el-option>
                </el-select>
              </span>
              <el-button icon="el-icon-search" size="medium" class="bottom_all but1" @click="(tableParam.page = 1), gettableData()">查 询</el-button>
              <el-button size="medium" class="bottom_all_two" style="margin-left:12px;" @click="init()">重 置</el-button>
            </div>
          </div>
        </el-collapse-transition>
        <div class="hr"></div>
        <div class="card">
          <div class="card_nav">
            <div>
              <el-button v-if="ButtonList.findIndex(res=>(res.buttonValue=='TIANJIA'))!==-1" size="small" class="bottom_all" style="margin-left: 0;" @click="addFromDate('添加'),fromDate.contractId = tableParam.contractId,fromDate.supplierId = tableParam.supplierId,fromDate.supplierName = tableParam.supplierName">
                <i class="icon iconfont iconicon_button_add" style="font-size: 12px;"></i>
                添加
              </el-button>
              <el-button v-if="ButtonList.findIndex(res=>(res.buttonValue=='RIYONG'))!==-1" size="small" class="bottom_three" @click="Update(1)">
                <i class="icon iconfont iconicon_button_startuse" style="font-size: 12px;"></i>
                启用
              </el-button>
              <el-button v-if="ButtonList.findIndex(res=>(res.buttonValue=='JINYONG'))!==-1" size="small" class="bottom_four" @click="Update(0)">
                <i class="icon iconfont iconicon_button_disable1" style="font-size: 12px;"></i>
                禁用
              </el-button>
            </div>
            <div>
              <el-dropdown :hide-on-click="false" trigger="click" style="margin: 0 20px;">
                <el-link :underline="false">
                  <span class="el-icon--left">
                    <i class="iconfont iconicon_button_filtrate"></i>
                  </span>
                  筛选
                </el-link>
                <el-dropdown-menu slot="dropdown">
                  <el-dropdown-item v-for="(item, index) in table" :key="index">
                    <el-checkbox v-model="item.status">{{ item.label }}</el-checkbox>
                  </el-dropdown-item>
                </el-dropdown-menu>
              </el-dropdown>
              <el-link v-if="ButtonList.findIndex(res=>(res.buttonValue=='DAOCHU'))!==-1" :underline="false" @click="load()">
                <span class="el-icon--left">
                  <i class="iconfont iconicon_button_export1"></i>
                </span>
                导出
              </el-link>
            </div>
          </div>
          <div v-loading="tableLoading" class="card_info" :style="style">
            <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width:100%" :data="tableData" tooltip-effect="dark" @selection-change="handleSelectionChange">
              <el-table-column align="center" type="selection"></el-table-column>
              <template v-for="(item, index2) in table">
                <el-table-column v-if="item.status" :key="index2" :label="item.label" align="center" :width="item.width">
                  <template slot-scope="scope">
                    <a v-if="item.label == '二维码'&&scope.row.quickMarkUrl&&ButtonList.findIndex(res=>(res.buttonValue=='EWEIM'))!==-1" class="table_link" :href="'/file/' +scope.row.quickMarkUrl" download>下载二维码</a>
                    <span v-if="scope.row.enable == 0 && item.label == '状态'" style="color:#969799;">禁用</span>
                    <span v-if="scope.row.enable == 1 && item.label == '状态'" style="color:#00A754;">启用</span>
                    <el-button v-if="item.label == '操作'&&ButtonList.findIndex(res=>(res.buttonValue=='XIUGAI'))!==-1" class="bottom_one" size="mini" @click="updateFromDateFun(scope.row)">
                      <i class="icon iconfont iconicon_button_modification" style="font-size: 12px;"></i>
                      修改
                    </el-button>
                    <span v-if="item.label !== '操作' && item.label !== '状态' && item.label !== '二维码'">{{ scope.row[item.prop] }}</span>
                  </template>
                </el-table-column>
              </template>
            </el-table>
          </div>
        </div>
      </el-main>
      <div class="card_bottom">
        <div class="card_bottom_left">
          <div class="top_page_totle">总共{{ total }}条</div>
          <el-pagination :current-page.sync="tableParam.page" :page-size="tableParam.pageSize" :page-sizes="[10, 20, 30, 40,50,100,200,500,1000]" layout="prev,pager,sizes,next,jumper" :total="total" @size-change="sizeChange" @current-change="gettableData()"></el-pagination>
        </div>
        <div>
          <el-button size="mini" icon="el-icon-refresh-right" class="bottom_all_two" @click="gettableData">刷新</el-button>
        </div>
      </div>
    </el-container>
    <!-- 添加 -->
    <el-dialog v-dialogDrag :visible.sync="addDialog" width="480px" :close-on-click-modal="false" :before-close="resetFromDate">
      <span slot="title" class="dialog-title">{{ addDialogTitle }}</span>
      <div class="dialoginfo">
        <el-form ref="reffromDate" :rules="rules" :inline="true" :model="fromDate" label-width="110px">
          <el-form-item prop="contractId" :rules="[{required: true,message: '请选择合同',trigger: 'blur',}]">
            <span slot="label" style="color: #ff0000">合同</span>
            <el-select v-model="fromDate.contractId" placeholder="请选择">
              <el-option v-for="item in contractIdList" :key="item.id" :label="item.contractNumber+item.supplierName" :value="item.id"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item prop="code">
            <span slot="label" style="color: #FF0000 ;">泵自编码</span>
            <el-input v-model="fromDate.code" placeholder="请输入" clearable @input="changecode('code')"></el-input>
          </el-form-item>
          <el-form-item prop="facilityTypeId">
            <span slot="label" style="color: #FF0000 ;">泵车类型</span>
            <el-select v-model="fromDate.facilityTypeId" filterable placeholder="请选择">
              <el-option v-for="item in equipmentTypelist" :key="item.id" :label="item.itemName" :value="item.id"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item prop="facilityNo">
            <span slot="label">车牌号</span>
            <el-input v-model="fromDate.facilityNo" placeholder="请输入" clearable></el-input>
          </el-form-item>
          <el-form-item prop="enable">
            <span slot="label">状态</span>
            <el-radio-group v-model="fromDate.enable">
              <el-radio :label="1">启用</el-radio>
              <el-radio :label="0">禁用</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="bottom_all_two" @click="resetFromDate">取 消</el-button>
        <el-button class="bottom_all" style="margin-left: 24px;" @click="submitPageFromDate()">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import mixin from "@/mixins/ICPSmixin.js";
import {
  queryPage,
  batchUpdateOrDelete,
  updateSortNum,
  saveOrUpdate,
  Download,
} from "@/api/supplier/equipment.js";
import { getUserInfo } from "@/utils/auth.js";
import { queryListByUserID, getDicType } from '@/api/common'
export default {
  mixins: [mixin],
  data() {
    return {
      UserInfo: "",
      contractIdList: [],//合同列表
      /*表格增删改查及下载接口*/
      queryPage: queryPage,
      batchUpdateOrDelete: batchUpdateOrDelete,
      updateSortNum: updateSortNum,
      saveOrUpdate: saveOrUpdate,
      DownloadURL: Download,
      /*表格数据*/
      table: [
        {
          label: "泵编码",
          width: "auto",
          prop: "code",
          status: true,
        },
        {
          label: "泵车类型",
          width: "auto",
          prop: "facilityType",
          status: true,
        },
        {
          label: "车牌号",
          width: "auto",
          prop: "facilityNo",
          status: true,
        },
        {
          label: "所属单位",
          width: "auto",
          prop: "supplierName",
          status: true,
        },
        {
          label: "二维码",
          width: "auto",
          prop: "quickMarkUrl",
          status: true,
        },
        {
          label: "状态",
          width: "auto",
          prop: "enable",
          status: true,
        },
        {
          label: "更新时间",
          width: "auto",
          prop: "createTime",
          status: true,
        },
        {
          label: "操作",
          width: "120",
          prop: "",
          status: true,
        },
      ],
      /*表单页类型，0为无树状，1为有树状，有树状在el-main加上display:flex*/
      pagesType: 0,
      /*添加表单数据*/
      rules: {
        code: [
          {
            required: true,
            message: "请输入设备自编码",
            trigger: "blur",
          },
        ],
        facilityNo: [
          {
            required: true,
            message: "请输入车牌号",
            trigger: "change",
          },
        ],
      },
      fromDate: {
        code: "",
        facilityType: "",
        facilityTypeId: "",
        facilityNo: "",
        supplierId: '',
        supplierName: "",
        enable: 1,
        contractId: ''
      },
      companylist: [],
      equipmentTypelist: [],
    };
  },
  async created() {
    /*根据供应商id获取合同list*/
    queryListByUserID().then((res) => {
      this.contractIdList = res.data;
    });
    this.UserInfo = await getUserInfo();
    this.fromDate.supplierId = this.UserInfo.userId
    /*存储拷贝的原初始化fromDate数据*/
    this.tableParam = {
      ...this.tableParam,
      code: "",
      facilityTypeId: "",
      facilityNo: "",
    };
    this.gettableData();
    getDicType({ code: "castingType" }).then((res) => {
      this.equipmentTypelist = res.data.items; //
    });
  },
  /*
   *copy(data)深拷贝数据,返回拷贝完的数据
   *gettableData获取列表数据
   *load下载
   *SortNum保持序列号
   * UpdateOrDelete禁用，启用，删除
   * submitFromDate保存更新数据
   */
  methods: {
    updateFromDateFun(data) {
      this.addDialog = true
      this.$refs.reffromDate.clearValidate();
      this.addDialogTitle = "修改"
      this.fromDate = { ...this.fromDate, ...data }
    },
    init() {
      /*重置数据*/
      this.tableParam.facilityTypeId = "";
      this.tableParam.code = "";
      this.tableParam.facilityNo = "";
      this.gettableData();
    },
    submitPageFromDate() {
      let _this = this;
      _this.$refs.reffromDate.validate((valid) => {
        if (valid) {
          this.fromDate.facilityType = this.$fromatTable(
            this.equipmentTypelist,
            this.fromDate.facilityTypeId,
            "id",
            "itemName"
          );
          let item = this.contractIdList.find((v) => v.id == this.fromDate.contractId)
          this.fromDate.companyId = item.exteriorCompanyId
          this.fromDate.supplierId = item.supplierId
          this.fromDate.supplierName = item.supplierName
          this.submitFromDate();
        } else {
          return false;
        }
      });
    },
    sizeChange(value) {
      this.tableParam.pageSize = value;
      this.gettableData();
    },
  },
};
</script>

<style lang="scss" scoped>
.checkcycdialoginfo {
  .el-input {
    width: 100px;
  }
  .el-select {
    width: 100px;
    margin-right: 20px;
  }
  .text {
    padding: 10px;
  }
}
.dialogOtherinfo {
  .el-pagination {
    padding: 10px 0;
  }
  min-height: 530px;
  .textarea {
    width: 870px;
  }

  .el-input,
  .el-select {
    width: 375px;
  }
}

.table_link {
  margin-left: 10px;
  color: $bg_color;
}

.table_link:hover {
  opacity: 0.8;
}

.el-input,
.el-select {
  width: 240px;
}
</style>
